Add a way to easily convert an AndroidAppWaker into a Waker#171
Add a way to easily convert an AndroidAppWaker into a Waker#171notgull wants to merge 1 commit intorust-mobile:mainfrom
Conversation
This commit adds a "waker()" method to AndroidAppWaker. It converts it into an `std::task::Waker`, which is the type of waker used by asynchronous tasks for scheduling. The goal is to allow AndroidAppWaker to be easily used to set up an asynchronous context. The implementation is very efficient, owing to the "static pointer" style of coding already used. The "wake" function just calls ALooper_wake, and cloning/dropping the waker is just a copy. Signed-off-by: John Nunley <dev@notgull.net>
|
Build failure is due to codebase rot |
|
Yeah, we're really lacking maintenance here, unfortunately. As always, I'm happy to submit PRs to tackle issues and implement features every once in a while in between other tasks, but need a second maintainer for review and approval. @rib can you update us on your availability and commitment towards this crate, or should we seek for a third maintainer to fill this review-gap? |
|
Regarding the PR itself, note that the result of a looper wake is very loosely defined and not to be relied on: #170 If there's any explicit |
|
Interesting. Does it have a chance of spuriously not waking up the event loop? |
|
@notgull according to their documentation, it would get batched up with other events, such that the event loop is "active" / "awake" but without ever seeing it return
But it also checked these before entering a With these findings, it'll miss events on |
|
I would prefer to just use eventfd. |
|
Same preference here, it's much more explicit than pretending every For redraws specifically, there's a preference to handle these via |
|
Sorry for only just coming around to look at this. This seems reasonable. Re: #170 and the way that wake events are documented: the point is just that when Regarding how winit handles Winit never specifically requires a In itself a So from Winit's point of view a Wake event on its own doesn't represent anything interesting that needs to be handled, unless it knows that it requested a wake up. The android backend for Winit effectively tracks when it's waiting for a wake up and so this code in Winit: android_activity::PollEvent::Wake => {
// In the X11 backend it's noted that too many false-positive wake ups
// would cause the event loop to run continuously. They handle this by
// re-checking for pending events (assuming they cover all
// valid reasons for a wake up).
//
// For now, user_events and redraw_requests are the only reasons to expect
// a wake up here so we can ignore the wake up if there are no events/requests.
// We also ignore wake ups while suspended.
self.pending_redraw |= self.redraw_flag.get_and_reset();
if !self.running
|| (!self.pending_redraw && !self.user_events_receiver.has_incoming())
{
return;
}
}is about ignoring Wake events when Winit has nothing it needs to do. In other words, an So in Winit specifically, it only has that special case for ignoring some Wake events and then apart from that, all events (including Wake events that are not ignored) will result in the same |
|
I think trying to make a This is the closest that the NDK officially lets you get to So even if you tried to punch lower and use |
Btw, I believe you can use A file descriptor from ref: https://android.googlesource.com/platform/bionic/%2B/android-8.0.0_r4/libc/SECCOMP_WHITELIST.TXT#70 |
|
Looking at this I realized there's a soundness issue with the current implementation of In particular we need to make sure The same would apply to |
This commit adds a "waker()" method to AndroidAppWaker. It converts it
into an
std::task::Waker, which is the type of waker used byasynchronous tasks for scheduling. The goal is to allow AndroidAppWaker
to be easily used to set up an asynchronous context.
The implementation is very efficient, owing to the "static pointer"
style of coding already used. The "wake" function just calls
ALooper_wake, and cloning/dropping the waker is just a copy.
Discussion questions:
waker()take&selforself? I chose the latter.